<template>
  <transition name="fade">
    <div class="xrk-loading" v-if="visibled">
      <div
        class="loading-container"
        :class="{ 'theme-white': theme === 'white' }"
      >
        <div class="loading-icon">
          <div class="loading-icon_spinner">
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
          </div>
          <img src="../../assets/min-logo.png" alt="" srcset="" />
        </div>
        <div class="loading-message" v-if="message">{{ message }}</div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "xrkLoading",
  data() {
    return {
      visibled: false,
    };
  },
  props: {
    message: {
      type: String,
    },
    theme: {
      type: String,
      default: "block",
    },
  },
  methods: {
    remove() {
      this.visibled = false;
      setTimeout(() => {
        document.body.removeChild(this.$el);
        this.$destroy();
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
.xrk-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  .loading-container {
    .loading-icon {
      position: relative;
      padding: 20px 0;
      .loading-icon_spinner {
        position: relative;
        width: 90px;
        max-width: 100%;
        height: 90px;
        max-height: 100%;
        margin: 0 auto;
        vertical-align: middle;
        animation: rotate 1.2s linear infinite;
        animation-timing-function: steps(12);
        i {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          color: rgb(255, 255, 255);
          &::after {
            display: block;
            width: 4px;
            height: 15%;
            margin: 0 auto;
            background-color: currentColor;
            border-radius: 40%;
            content: " ";
          }
          &:nth-of-type(1) {
            transform: rotate(30deg);
            opacity: 1;
          }
          &:nth-of-type(2) {
            transform: rotate(60deg);
            opacity: 0.9375;
          }
          &:nth-of-type(3) {
            transform: rotate(90deg);
            opacity: 0.875;
          }
          &:nth-of-type(4) {
            transform: rotate(120deg);
            opacity: 0.8125;
          }
          &:nth-of-type(5) {
            transform: rotate(150deg);
            opacity: 0.75;
          }
          &:nth-of-type(6) {
            transform: rotate(180deg);
            opacity: 0.6875;
          }
          &:nth-of-type(7) {
            transform: rotate(210deg);
            opacity: 0.625;
          }
          &:nth-of-type(8) {
            transform: rotate(240deg);
            opacity: 0.5625;
          }
          &:nth-of-type(9) {
            transform: rotate(270deg);
            opacity: 0.5;
          }
          &:nth-of-type(10) {
            transform: rotate(300deg);
            opacity: 0.4375;
          }
          &:nth-of-type(11) {
            transform: rotate(330deg);
            opacity: 0.375;
          }
          &:nth-of-type(12) {
            transform: rotate(360deg);
            opacity: 0.3125;
          }
        }
      }
      img {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 20px;
        height: 20px;
      }
    }
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    width: 160px;
    border-radius: 16px;
    padding: 20px;
    background-color: rgba(0, 0, 0, 0.7);
    .loading-message {
      text-align: center;
      color: #fff;
    }
    &.theme-white {
      background-color: rgb(255, 255, 255);
      box-shadow: 0 0 8px rgba(0, 0, 0, 0.178);
      .loading-icon_spinner i {
        color: rgb(248, 182, 39);
      }
      .loading-message {
        color: #323233;
      }
    }
  }
  .loading-message {
    font-size: 12px;
    color: #fff;
  }
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>